from src.translation_file.datamodel import TranModel
from src.translation_file.translation_file import TranslationFile
from src.huey_init._huey import huey
from src.tools.dms_operator import dmsoperator

@huey.task(context=True)
def run_translation_task(tran_model: TranModel, task=None):
    tran = TranslationFile()
    for file_obj in tran_model.exchange_info.get("docList"):
        res = tran.translation_file(tran_model.language, file_obj, task.id)
        exchange_info = {
            "functionType": tran_model.exchange_info.get("functionType"),
            "taskType": tran_model.exchange_info.get("taskType"),
            "taskDocumentType": tran_model.exchange_info.get("taskDocumentType"),
            "executionType": tran_model.exchange_info.get("executionType"),
            "isSuccess": True,
            "dmsTaskId": tran_model.exchange_info.get("dmsTaskId"),
            "docId": file_obj["docId"],
            "taskDocId": file_obj["taskDocId"],
            "resultFirstFilePath": res[0],
            "resultSecondFilePath": res[1],
            "aiTaskId": task.id
        }
        print(res)
        dmsoperator.post_exchange_info(exchange_info)
